﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace DocumentManager
{
    public partial class Login : Form
    {
        public Boolean IsAdmin = false;
        private int LoginAttempts = 0;
        public Login()
        {
            InitializeComponent();
            lbInvalidLogin.Visible = false;
        }

        private void btnGo_Click(object sender, EventArgs e)
        {
            LoginAttempts++;
            lbInvalidLogin.Visible = false;
            if (txtPassPhrase.Text.Trim().Equals("spec"))
            {
                GlobalSettings.Settings["Admin"] = true;
                IsAdmin = true;
                this.Close();
            }
            else
            {
                if (LoginAttempts > 3)
                {
                    IsAdmin = false;
                    this.Close();
                }
                else
                {
                    lbInvalidLogin.Text = "Invalid Login (x" + LoginAttempts + ").";
                    lbInvalidLogin.Visible = true;
                    IsAdmin = false;
                }
            }
        }

        private void Login_Load(object sender, EventArgs e)
        {
            
        }

        private void txtPassPhrase_KeyUp(object sender, KeyEventArgs e)
        {
            e.Handled = true;
            switch (e.KeyCode)
            {
                case Keys.Enter:
                    btnGo.PerformClick();
                    break;
                default:
                    e.Handled = true;
                    break;
            }
        }
    }
}
